package com.cet.designpatterns.principle.interfacesegregation;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-08-25 16:53
 **/
public class Segregation01 {
    public static void main(String[] args) {
        A a = new A();
        //A类通过接口依赖B类
        a.depend1(new B());
        a.depend2(new B());
        a.depend3(new B());

        C c = new C();
        //C类通过接口依赖D类
        c.depend1(new D());
        c.depend4(new D());
        c.depend5(new D());
    }
}

interface interface1{
    void operation1();
}

interface interface2{

    void operation2();

    void operation3();
}

interface interface3{

    void operation4();

    void operation5();
}

class A {
    public void depend1(interface1 i) {
        i.operation1();
    }

    public void depend2(interface2 i){
        i.operation2();
    }

    public void depend3(interface2 i){
        i.operation3();
    }
}


class B implements interface1, interface2{
    @Override
    public void operation1() {
        System.out.println(this.getClass().getSimpleName()+"实现了方法operation1");
    }

    @Override
    public void operation2() {
        System.out.println(this.getClass().getSimpleName()+"实现了方法operation2");
    }

    @Override
    public void operation3() {
        System.out.println(this.getClass().getSimpleName()+"实现了方法operation3");
    }
}

class C {
    public void depend1(interface1 i) {
        i.operation1();
    }

    public void depend4(interface3 i){
        i.operation4();
    }

    public void depend5(interface3 i){
        i.operation5();
    }
}

class D implements interface1, interface3{

    @Override
    public void operation1() {
        System.out.println(this.getClass().getSimpleName()+"实现了方法operation1");
    }

    @Override
    public void operation4() {
        System.out.println(this.getClass().getSimpleName()+"实现了方法operation4");
    }

    @Override
    public void operation5() {
        System.out.println(this.getClass().getSimpleName()+"实现了方法operation5");
    }
}


